package com.news.news.web;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.github.pagehelper.PageInfo;
import com.news.news.modle.User;
import com.news.news.service.UserCenterService;
import com.news.news.service.UsersService;
import com.news.news.util.CommonResult;
import com.news.news.util.JWTUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping(path = "/userCenter/userCtl")
public class UserCenterController {
    @Resource
    UserCenterService userCenterService;


    @GetMapping(value = "/information")
    public CommonResult information(@RequestHeader("userToken") String userToken) {
        User user =  userCenterService.information(userToken);
        CommonResult commonResult = new CommonResult(200, user, "成功");
        return commonResult;
    }

    @PostMapping(value = "/update")
    public CommonResult update(@RequestBody User user) {
         userCenterService.update(user);
        CommonResult commonResult = new CommonResult(200, null, "成功");
        return commonResult;
    }
    @GetMapping(value = "/xzOldPsw")
    public CommonResult xzOldPsw(@RequestHeader("userToken") String userToken,String password) {
      String msg =  userCenterService.xzOldPsw(userToken,password);
      CommonResult commonResult = new CommonResult(200, null,msg);
      return commonResult;
    }
    @GetMapping(value = "/saveNewPsw")
    public CommonResult saveNewPsw(@RequestHeader("userToken") String userToken,String password) {
       userCenterService.saveNewPsw(userToken,password);
        CommonResult commonResult = new CommonResult(200, null,"修改成功");
        return commonResult;
    }
}
